package com.ant.storage.controller;

import com.ant.storage.common.ResultPage;
import com.ant.storage.pojo.InventoryCheck;
import com.ant.storage.service.IInventoryCheckService;
import com.ant.storage.common.PageRecv;
import com.ant.storage.common.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/inventoryCheck")
@Api(tags = "库存盘点接口")
public class InventoryCheckController {

    @Autowired
    IInventoryCheckService inventoryCheckService;

    @ApiOperation(value = "新增库存盘点(编辑)")
    @PostMapping("/addInventoryCheckEdit")
    @Transactional(rollbackFor = Exception.class)
    public ResultVo addInventoryCheckEdit(@RequestBody @Valid InventoryCheck inventoryCheck, BindingResult bindingResult){
        return inventoryCheckService.addInventoryCheckEdit(inventoryCheckService.editVerification(inventoryCheck,bindingResult));
    }

    @ApiOperation(value = "新增库存盘点(盘点完成)")
    @PostMapping("/addInventoryCheck")
    @Transactional(rollbackFor = Exception.class)
    public ResultVo addInventoryCheck(@RequestBody @Valid InventoryCheck inventoryCheck, BindingResult bindingResult){
        return inventoryCheckService.addInventoryCheckConfirm(inventoryCheckService.confirmVerification(inventoryCheck,bindingResult));
    }

    @ApiOperation(value = "修改库存盘点(编辑)")
    @PostMapping("/updateInventoryCheckEdit")
    @Transactional(rollbackFor = Exception.class)
    public ResultVo updateInventoryCheckEdit(@RequestBody InventoryCheck inventoryCheck){
        return inventoryCheckService.updateInventoryCheckEdit(inventoryCheck);
    }

    @ApiOperation(value = "修改库存盘点(确认)")
    @PostMapping("/inventoryCheckEditConfirm")
    @Transactional(rollbackFor = Exception.class)
    public ResultVo inventoryCheckEditConfirm(@RequestBody InventoryCheck inventoryCheck){
        return inventoryCheckService.inventoryCheckEditConfirm(inventoryCheck);
    }

    @ApiOperation(value = "库存盘点查询")
    @PostMapping("/queryInventoryCheck")
    public ResultPage queryInventoryCheck(@RequestBody PageRecv<InventoryCheck>pageRecv){
        return inventoryCheckService.queryInventoryCheck(pageRecv);
    }
}
